package com.example.xingzai.myapplication;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.Random;

import adapter.MyAdapter;
import adapter.Group;

public class ComplexActivity extends AppCompatActivity {

    private GridView gridView;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_complex);

        gridView = (GridView) findViewById(R.id.gridView);
        gridView.setNumColumns(1);

        MyAdapter myAdapter = new MyAdapter(doCreateData(),
                ComplexActivity.this);
        gridView.setAdapter(myAdapter);
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(ComplexActivity.this, position + "", Toast.LENGTH_SHORT).show();
            }
        });
    }

    ArrayList<Group> doCreateData() {
        ArrayList<Group> persons = new ArrayList<Group>();
        for (int i = 0; i < 20; i++) {
            Group p = new Group(i + "", new Random().nextInt(100) + "");
            persons.add(p);
        }
        return persons;
    }
}
